package com.explorati.interview.interview.chapterfifteen;

public class InsertSort {

	public static void insertSort(int[] arr) {
		for (int i = 1; i < arr.length; i++) {
			int temp = 0;
			// 寻找元素arr[i]合适的插入位置
			for (int j = i; j > 0 && arr[j - 1] > arr[j]; j--) {
				temp = arr[j - 1];
				arr[j - 1] = arr[j];
				arr[j] = temp;
			}
		}
	}

	public static void main(String[] args) {
		int[] arr = { 4, 3, 52, 12, 53, 56, 78 };
		insertSort(arr);
		for (int i : arr) {
			System.out.print(i + "\t");
		}
	}
}
